package com.hbut.system.controller.sysuser;

import com.hbut.common.core.Controller.BaseController;
import com.hbut.common.core.constants.HttpConstants;
import com.hbut.common.core.domain.R;
import com.hbut.common.core.domain.vo.LoginUserVO;
import com.hbut.system.domain.sysuser.dto.LoginDTO;
import com.hbut.system.domain.sysuser.dto.SysUserSaveDTO;
import com.hbut.system.domain.sysuser.vo.SysUserVO;
import com.hbut.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员用户 API")
public class SysUserController extends BaseController {
    @Autowired
    ISysUserService serviceImp;

    @Operation(summary = "管理员登录",description = "管理员登录")
    @ApiResponse(responseCode = "1000",description = "管理员登录成功")
    @ApiResponse(responseCode = "2000",description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3000",description = "操作失败")
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO){
       return serviceImp.login(loginDTO);
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return serviceImp.info(token);
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toR(serviceImp.logout(token));
    }

    @Operation(summary = "新增管理员",description = "根据提供的信息新增管理员用户")
    @PostMapping("/add")
    @ApiResponse(responseCode = "1000",description = "新增管理员成功")
    @ApiResponse(responseCode = "2000",description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){   //参数为对象
        return toR(serviceImp.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户",description = "通过用户 id 删除用户")
    @ApiResponse(responseCode = "1000",description = "成功删除用户")
    @ApiResponse(responseCode = "2000",description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102",description = "⽤⼾不存在")
    @Parameters(value = {
            @Parameter(name = "userId",in = ParameterIn.PATH,description = "用户ID")
    })
    public R<Void> delete(@PathVariable Long userId){   //参数: url 中的路径参数
        return null;
    }

    @Operation(summary = "⽤⼾详情", description = "根据查询条件查询⽤⼾详情")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "⽤⼾性别")
    })
    @GetMapping("/detail")
    @ApiResponse(responseCode = "1000", description = "成功获取⽤⼾信息")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
    public R<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex){
         return null;
    }
}
